import matplotlib.pyplot as plt
import numpy as np
import os

def cr():
    x_data = ['MID', 'EDF', 'INS', 'SRPT', 'FB', 'THR', 'OPTFB', 'RM', 'SEDF', 'SALL', 'FIFO', 'FEDF']
    cr_data = [0.7764323320446002, 0.9798526261870666, 0.9921451040480338, 0.8614297736859432, 0.9751327152501925, 0.9751129083673007, 0.9859394708269289, 0.9362742180803927, 0.9856175219182627, 0.853183624344755, 0.38535126258789576, 0.385237344806816]
    plt.bar(x_data,cr_data,color="deepskyblue",label="Average Completion Rate")

    #line
    ave_us_data = [0.7161634000000002, 0.8809191999999999, 0.8931114000000001, 0.7718346000000001, 0.8768362000000001, 0.87682, 0.8874591999999999, 0.8683315999999998, 0.8874038, 0.7569433999999999, 0.33369020000000005, 0.33363460000000006]
    worst_us_data =  [0.71506, 0.87971, 0.89236, 0.76924, 0.87424, 0.87424, 0.88553, 0.86768, 0.88537, 0.75436, 0.32926, 0.32926]
    ave_Comp_ratio = [0.7961971361230934, 0.9793649664250457, 0.9929196869302264, 0.858089785209232, 0.9748256770578556, 0.9748076666518432, 0.9866358340374437, 0.9653706586027484, 0.9865742428958956, 0.8415344421221151, 0.3709812336016365, 0.3709194201093965]
    worst_Comp_ratio =  [0.794970427358029, 0.9780206341441722, 0.9920843153822209, 0.8552052296882643, 0.9719393427313558, 0.9719393427313558, 0.9844910392671321, 0.9646462400498066, 0.9843131587139236, 0.8386623382398719, 0.36605594343398407, 0.36605594343398407]
    plt.plot(x_data, ave_us_data, color = "sandybrown", marker='o', ms=3, label="ave_us")
    plt.plot(x_data, worst_us_data, color = "crimson", marker='o', ms=3, label="worst_us")
    plt.plot(x_data, ave_Comp_ratio, color = "plum", marker='o', ms=3, label="ave_compratio")
    plt.plot(x_data, worst_Comp_ratio, color = "indigo", marker='o', ms=3, label="worst_compratio")
    plt.legend()
    plt.title('Completion rate & US & CompRatio')
    graph_path = os.path.dirname(os.path.abspath(__file__)) + '/graph/'
    if not os.path.isdir(graph_path):
        os.makedirs(graph_path)
    file_name = graph_path + __file__.split('/')[-1].split('.')[0]
    plt.savefig(f"{file_name}.pdf", bbox_inches='tight')
    plt.close()


if __name__ == '__main__':
    cr()
        
